package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import com.elder.business.domain.ElderMedicatePaln;
import com.elder.business.service.IElderMedicatePalnService;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 用药计划Controller
 * 
 * @author elder
 * @date 2024-04-20
 */
@RestController
public class ElderMedicatePalnController extends BaseController
{
    @Autowired
    private IElderMedicatePalnService elderMedicatePalnService;

    /**
     * 查询用药计划列表
     */
    @Anonymous
    @GetMapping("/medicate/paln/list")
    public TableDataInfo list(@NotNull Long userId,@NotNull Long elderId,Integer planType, Integer pageNum, Integer pageSize)  {
        return elderMedicatePalnService.getElderMedicatePalnList(userId,elderId,planType,pageNum,pageSize);
    }

//    /**
//     * 导出用药计划列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:paln:export')")
//    @Log(title = "用药计划", businessType = BusinessType.EXPORT)
//    @PostMapping("/medicate/paln/export")
//    public void export(HttpServletResponse response, ElderMedicatePaln elderMedicatePaln)
//    {
//        List<ElderMedicatePaln> list = elderMedicatePalnService.selectElderMedicatePalnList(elderMedicatePaln);
//        ExcelUtil<ElderMedicatePaln> util = new ExcelUtil<ElderMedicatePaln>(ElderMedicatePaln.class);
//        util.exportExcel(response, list, "用药计划数据");
//    }

    /**
     * 获取用药计划详细信息
     */
    @Anonymous
    @GetMapping(value = "/medicate/paln/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(elderMedicatePalnService.selectElderMedicatePalnById(id));
    }

    /**
     * 新增用药计划
     */
    @Anonymous
    @Log(title = "用药计划", businessType = BusinessType.INSERT)
    @PostMapping("/medicate/paln")
    public AjaxResult add(@RequestBody ElderMedicatePaln elderMedicatePaln)
    {
        return elderMedicatePalnService.insertElderMedicatePaln(elderMedicatePaln);
    }

    /**
     * 修改用药计划
     */
    @Anonymous
    @Log(title = "用药计划", businessType = BusinessType.UPDATE)
    @PutMapping("/medicate/paln")
    public AjaxResult edit(@RequestBody ElderMedicatePaln elderMedicatePaln)
    {
        return toAjax(elderMedicatePalnService.updateElderMedicatePaln(elderMedicatePaln));
    }

    /**
     * 删除用药计划
     */
    @Anonymous
    @Log(title = "用药计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/medicate/paln/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elderMedicatePalnService.deleteElderMedicatePalnByIds(ids));
    }

    @Anonymous
    @GetMapping(value = "/del/medicate/paln/{id}")
    public AjaxResult delete(@PathVariable("id") Long id)
    {
        return success(elderMedicatePalnService.deleteElderMedicatePalnById(id));
    }
}
